package com.order_system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.order_system.constants.Code;
import com.order_system.entity.Product;
import com.order_system.entity.Purchase;
import com.order_system.entity.ResModel;
import com.order_system.mapper.ProductMapper;
import com.order_system.mapper.PurchaseMapper;
import com.order_system.service.ProductService;
import com.order_system.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 李阳
 * @since 2023-01-06
 */
@Service
public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> implements PurchaseService {

    @Autowired
    private ProductService productService;

    @Override
    public ResModel getList() {
        List<Purchase> list = list();
        for (Purchase purchase : list) {
            Product product = productService.selectById(purchase.getProductId());
            purchase.setProduct(product);
        }
        return ResModel.success(Code.SUCCESS,list);
    }
}
